package com.dragon.backstage.domain.param.role;

import com.dragon.common.utils.AjaxResult;
import com.dragon.interfaces.constant.RoleConstant;
import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;

/**
 * 角色模块-更改角色状态请求参数
 *
 * @author dragon
 * @version 1.0
 * @date 2024/8/7 17:10
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(title = "角色模块-更改角色状态请求参数")
public class RoleChangeStatusParam {

    /**
     * 角色ID
     */
    @Schema(title = "角色ID", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long roleId;

    /**
     * 角色状态（1正常 0禁用）
     */
    @Builder.Default
    @Schema(title = "角色状态（1正常 0禁用）", requiredMode = Schema.RequiredMode.REQUIRED)
    private Byte status = 1;


    /**
     * 参数校验
     */
    public static AjaxResult<Void> check(RoleChangeStatusParam param) {
        List<Byte> statusArr = Lists.newArrayList(
            RoleConstant.STATUS_NORMAL,
            RoleConstant.STATUS_DISABLED
        );

        if (Objects.isNull(param)) {
            return AjaxResult.failed("请求参数为空");
        }
        if (Objects.isNull(param.getRoleId()) || param.getRoleId().equals(0L)) {
            return AjaxResult.failed("角色ID不能为空");
        }
        if (Objects.isNull(param.getStatus())) {
            return AjaxResult.failed("角色状态不能为空");
        }
        if (!statusArr.contains(param.getStatus())) {
            return AjaxResult.failed("角色状态值不符");
        }

        return AjaxResult.succeed();
    }

}
